/*
 * @(#)FormSubmissionHtml.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.form.dao;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import oracle.sql.BLOB;

import com.dcivision.form.bean.FormSubmissionHtml;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.DataSourceFactory;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;

/**
  FormSubmissionHtmlDAObject.java

  This class is the data access bean for table "FORM_SUBMISSION_HTML".

  @author      Vera Wang
  @company     DCIVision Limited
  @creation date   20/05/2004
  @version     $Revision: 1.8 $
*/

public class FormSubmissionHtmlDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.8 $";

  public static final String TABLE_NAME = "FORM_SUBMISSION_HTML";

  public FormSubmissionHtmlDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("FORM_RECORD_ID");
    this.vecDBColumn.add("FORM_PAGE_ID");
    this.vecDBColumn.add("FORM_SECTION_ID");
    this.vecDBColumn.add("PAGE_HTML");
    this.vecDBColumn.add("VERSION");
    this.vecDBColumn.add("STATUS");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
      	sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          return(tmpFormSubmissionHtml);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());

    synchronized(dbConn) {
      try {
      	sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");

        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }

        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt<pageSize) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          tmpFormSubmissionHtml.setRecordCount(totalNumOfRecord);
          tmpFormSubmissionHtml.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpFormSubmissionHtml);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }

  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
      	sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          result.add(tmpFormSubmissionHtml);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }

  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    FormSubmissionHtml tmpFormSubmissionHtml = (FormSubmissionHtml)((FormSubmissionHtml)obj).clone();
    
    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        if (DataSourceFactory.DB_ORACLE!=DataSourceFactory.getDatabaseType()) {
          sqlStat.append("INSERT ");
          sqlStat.append("INTO   FORM_SUBMISSION_HTML(ID, FORM_RECORD_ID, FORM_PAGE_ID, FORM_SECTION_ID, PAGE_HTML, VERSION, STATUS, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
          sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
          preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
          setPrepareStatement(preStat, 1, nextID);
          setPrepareStatement(preStat, 2, tmpFormSubmissionHtml.getFormRecordID());
          setPrepareStatement(preStat, 3, tmpFormSubmissionHtml.getFormPageID());
          setPrepareStatement(preStat, 4, tmpFormSubmissionHtml.getFormSectionID());
          setPrepareStatement(preStat, 5, tmpFormSubmissionHtml.getPageHtml());
          setPrepareStatement(preStat, 6, tmpFormSubmissionHtml.getVersion());
          setPrepareStatement(preStat, 7, tmpFormSubmissionHtml.getStatus());
          setPrepareStatement(preStat, 8, GlobalConstant.RECORD_STATUS_ACTIVE);
          setPrepareStatement(preStat, 9, new Integer(0));
          setPrepareStatement(preStat, 10, sessionContainer.getUserRecordID());
          setPrepareStatement(preStat, 11, currTime);
          setPrepareStatement(preStat, 12, sessionContainer.getUserRecordID());
          setPrepareStatement(preStat, 13, currTime);
          preStat.executeUpdate();
        } else {
          sqlStat.append("INSERT ");
          sqlStat.append("INTO   FORM_SUBMISSION_HTML(ID, FORM_RECORD_ID, FORM_PAGE_ID, FORM_SECTION_ID, PAGE_HTML, VERSION, STATUS, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
          sqlStat.append("VALUES (?, ?, ?, ?, EMPTY_BLOB(), ?, ?, ?, ?, ?, ?, ?, ?) ");
          preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
          setPrepareStatement(preStat, 1, nextID);
          setPrepareStatement(preStat, 2, tmpFormSubmissionHtml.getFormRecordID());
          setPrepareStatement(preStat, 3, tmpFormSubmissionHtml.getFormPageID());
          setPrepareStatement(preStat, 4, tmpFormSubmissionHtml.getFormSectionID());
          setPrepareStatement(preStat, 5, tmpFormSubmissionHtml.getVersion());
          setPrepareStatement(preStat, 6, tmpFormSubmissionHtml.getStatus());
          setPrepareStatement(preStat, 7, GlobalConstant.RECORD_STATUS_ACTIVE);
          setPrepareStatement(preStat, 8, new Integer(0));
          setPrepareStatement(preStat, 9, sessionContainer.getUserRecordID());
          setPrepareStatement(preStat, 10, currTime);
          setPrepareStatement(preStat, 11, sessionContainer.getUserRecordID());
          setPrepareStatement(preStat, 12, currTime);
          preStat.executeUpdate();
          preStat.close();

          ResultSet rs = null;
          BLOB blob = null;
          sqlStat = new StringBuffer();
          sqlStat.append("SELECT  PAGE_HTML ");
          sqlStat.append("FROM  FORM_SUBMISSION_HTML ");
          sqlStat.append("WHERE ID = " + nextID);
          preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
          rs = preStat.executeQuery();
          if (rs.next()) {
            blob = (BLOB)rs.getBlob("PAGE_HTML");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
              ObjectOutputStream out = new ObjectOutputStream(baos);
              out.writeObject(tmpFormSubmissionHtml.getPageHtml());
              out.flush();
            } catch (java.io.IOException ioe) {
              log.error("Cannot write object stream", ioe);
              new java.sql.SQLException("Cannot write object stream");
            }
            blob.putBytes(1, baos.toByteArray());

            sqlStat = new StringBuffer();
            sqlStat.append("UPDATE  FORM_SUBMISSION_HTML ");
            sqlStat.append("SET PAGE_HTML = ? ");
            sqlStat.append("WHERE ID = ? ");
            PreparedStatement preStat2 = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            preStat2.setBlob(1, blob);
            preStat2.setInt(2, nextID.intValue());
            preStat2.executeUpdate();
            try { preStat2.close(); } catch (Exception ignore) {} finally {preStat2 = null; }
          }
          try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        }
        tmpFormSubmissionHtml.setID(nextID);
        tmpFormSubmissionHtml.setCreatorID(sessionContainer.getUserRecordID());
        tmpFormSubmissionHtml.setCreateDate(currTime);
        tmpFormSubmissionHtml.setUpdaterID(sessionContainer.getUserRecordID());
        tmpFormSubmissionHtml.setUpdateDate(currTime);
        tmpFormSubmissionHtml.setUpdateCount(new Integer(0));
        tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
        tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
        
        return(tmpFormSubmissionHtml);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    FormSubmissionHtml tmpFormSubmissionHtml = (FormSubmissionHtml)((FormSubmissionHtml)obj).clone();

    synchronized(dbConn) {
        try {
          int updateCnt = 0;
          Timestamp currTime = Utility.getCurrentTimestamp();
          if (DataSourceFactory.DB_ORACLE!=DataSourceFactory.getDatabaseType()) {
  log.debug("Normal update of blob");
  			sqlStat.append("UPDATE FORM_SUBMISSION_HTML ");
  			sqlStat.append("SET  FORM_RECORD_ID=?, FORM_PAGE_ID=?, FORM_SECTION_ID=?, PAGE_HTML=?, VERSION=?, STATUS=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
  			sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
 			preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 			setPrepareStatement(preStat, 1, tmpFormSubmissionHtml.getFormRecordID());
 			setPrepareStatement(preStat, 2, tmpFormSubmissionHtml.getFormPageID());
 			setPrepareStatement(preStat, 3, tmpFormSubmissionHtml.getFormSectionID());
 			setPrepareStatement(preStat, 4, tmpFormSubmissionHtml.getPageHtml());
 			setPrepareStatement(preStat, 5, tmpFormSubmissionHtml.getVersion());
 			setPrepareStatement(preStat, 6, tmpFormSubmissionHtml.getStatus());
 			setPrepareStatement(preStat, 7, new Integer(tmpFormSubmissionHtml.getUpdateCount().intValue() + 1));
 			setPrepareStatement(preStat, 8, sessionContainer.getUserRecordID());
 			setPrepareStatement(preStat, 9, currTime);
 			setPrepareStatement(preStat, 10, tmpFormSubmissionHtml.getID());
 			setPrepareStatement(preStat, 11, tmpFormSubmissionHtml.getUpdateCount());
            updateCnt = preStat.executeUpdate();
          } else {
          	sqlStat.append("UPDATE FORM_SUBMISSION_HTML ");
			sqlStat.append("SET  FORM_RECORD_ID=?, FORM_PAGE_ID=?, FORM_SECTION_ID=?, PAGE_HTML=EMPTY_BLOB(), VERSION=?, STATUS=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
			sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
            preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            setPrepareStatement(preStat, 1, tmpFormSubmissionHtml.getFormRecordID());
 			setPrepareStatement(preStat, 2, tmpFormSubmissionHtml.getFormPageID());
 			setPrepareStatement(preStat, 3, tmpFormSubmissionHtml.getFormSectionID());
 			setPrepareStatement(preStat, 4, tmpFormSubmissionHtml.getVersion());
 			setPrepareStatement(preStat, 5, tmpFormSubmissionHtml.getStatus());
 			setPrepareStatement(preStat, 6, new Integer(tmpFormSubmissionHtml.getUpdateCount().intValue() + 1));
 			setPrepareStatement(preStat, 7, sessionContainer.getUserRecordID());
 			setPrepareStatement(preStat, 8, currTime);
 			setPrepareStatement(preStat, 9, tmpFormSubmissionHtml.getID());
 			setPrepareStatement(preStat, 10, tmpFormSubmissionHtml.getUpdateCount());
            updateCnt = preStat.executeUpdate();
            if(updateCnt>0){
  log.debug("Begin special handling for oracle update blob");
              ResultSet rs = null;
              BLOB blob = null;
              sqlStat = new StringBuffer();
              sqlStat.append("SELECT  PAGE_HTML ");
              sqlStat.append("FROM  FORM_SUBMISSION_HTML ");
              sqlStat.append("WHERE ID = " + tmpFormSubmissionHtml.getID());
              preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
              rs = preStat.executeQuery();
              if (rs.next()) {
                blob = (BLOB)rs.getBlob("PAGE_HTML");
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                try {
                  ObjectOutputStream out = new ObjectOutputStream(baos);
                  out.writeObject(tmpFormSubmissionHtml.getPageHtml());
                  out.flush();
  log.debug("Finished writing blob");
                } catch (java.io.IOException ioe) {
                  log.error("Cannot write object stream", ioe);
                  new java.sql.SQLException("Cannot write object stream");
                }
                blob.putBytes(1, baos.toByteArray());

                sqlStat = new StringBuffer();
                sqlStat.append("UPDATE  FORM_SUBMISSION_HTML ");
                sqlStat.append("SET PAGE_HTML = ? ");
                sqlStat.append("WHERE ID = ? ");
                PreparedStatement preStat2 = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                preStat2.setBlob(1, blob);
                preStat2.setInt(2, tmpFormSubmissionHtml.getID().intValue());
                preStat2.executeUpdate();
  log.debug("Finished updating parameter_object");
                try { preStat2.close(); } catch (Exception ignore) {} finally {preStat2 = null; }
              }
              try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
            }
          }

          if (updateCnt == 0) {
            throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
          } else {         	
          	tmpFormSubmissionHtml.setUpdaterID(sessionContainer.getUserRecordID());
            tmpFormSubmissionHtml.setUpdateDate(currTime);
            tmpFormSubmissionHtml.setUpdateCount(new Integer(tmpFormSubmissionHtml.getUpdateCount().intValue() + 1));
            tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
            tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
            
            return(tmpFormSubmissionHtml);
          }
        } catch (ApplicationException appEx) {
          throw appEx;
        } catch (SQLException sqle) {
          log.error(sqle, sqle);
          throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
        } catch (Exception e) {
          log.error(e, e);
          throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
        } finally {
          try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        }
      }
  }

  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    FormSubmissionHtml tmpFormSubmissionHtml = (FormSubmissionHtml)((FormSubmissionHtml)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpFormSubmissionHtml.getID());
        setPrepareStatement(preStat, 2, tmpFormSubmissionHtml.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpFormSubmissionHtml);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    FormSubmissionHtml tmpFormSubmissionHtml = (FormSubmissionHtml)this.oldValue;

    if (tmpFormSubmissionHtml != null) {
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getID()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getFormRecordID()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getFormPageID()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getFormSectionID()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getPageHtml()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getVersion()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getStatus()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getUpdateDate()));
    }

    tmpFormSubmissionHtml = (FormSubmissionHtml)obj;
    if (tmpFormSubmissionHtml != null) {
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getID()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getFormRecordID()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getFormPageID()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getFormSectionID()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getPageHtml()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getVersion()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getStatus()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpFormSubmissionHtml.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }

  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/
  public synchronized AbstractBaseObject getByRecordIDPageID(Integer formRecordID,Integer formPageID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.FORM_RECORD_ID = ? AND A.FORM_PAGE_ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, formRecordID);
        this.setPrepareStatement(preStat, 2, formPageID);
        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setFormSectionID(getResultSetInteger(rs, "FORM_Section_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          return(tmpFormSubmissionHtml);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }


  public synchronized List getByRecordIDPageIDList(Integer formRecordID,Integer formPageID)  throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
      	sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.FORM_RECORD_ID = ? AND A.FORM_PAGE_ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, formRecordID);
        this.setPrepareStatement(preStat, 2, formPageID);
        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setFormSectionID(getResultSetInteger(rs, "FORM_Section_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          result.add(tmpFormSubmissionHtml);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  public synchronized List getListByRecordID(Integer formRecordID)  throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.FORM_RECORD_ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, formRecordID);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setFormSectionID(getResultSetInteger(rs, "FORM_Section_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          result.add(tmpFormSubmissionHtml);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  public synchronized AbstractBaseObject getByRecordIDPageIDSectionID(Integer formRecordID,Integer formPageID,Integer formSectionID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
        sqlStat.append("WHERE  A.FORM_RECORD_ID = ? AND A.FORM_PAGE_ID = ? AND A.FORM_SECTION_ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, formRecordID);
        this.setPrepareStatement(preStat, 2, formPageID);
        this.setPrepareStatement(preStat, 3, formSectionID);
        this.setPrepareStatement(preStat, 4, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          FormSubmissionHtml tmpFormSubmissionHtml = new FormSubmissionHtml();
          tmpFormSubmissionHtml.setID(getResultSetInteger(rs, "ID"));
          tmpFormSubmissionHtml.setFormRecordID(getResultSetInteger(rs, "FORM_RECORD_ID"));
          tmpFormSubmissionHtml.setFormPageID(getResultSetInteger(rs, "FORM_PAGE_ID"));
          tmpFormSubmissionHtml.setFormSectionID(getResultSetInteger(rs, "FORM_Section_ID"));
          tmpFormSubmissionHtml.setPageHtml(getResultSetObject(rs, "PAGE_HTML"));
          tmpFormSubmissionHtml.setVersion(getResultSetString(rs, "VERSION"));
          tmpFormSubmissionHtml.setStatus(getResultSetString(rs, "STATUS"));
          tmpFormSubmissionHtml.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpFormSubmissionHtml.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpFormSubmissionHtml.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpFormSubmissionHtml.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpFormSubmissionHtml.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpFormSubmissionHtml.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpFormSubmissionHtml.setCreatorName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getCreatorID()));
          tmpFormSubmissionHtml.setUpdaterName(UserInfoFactory.getUserFullName(tmpFormSubmissionHtml.getUpdaterID()));
          return(tmpFormSubmissionHtml);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  public synchronized boolean getBooleanByRecordID(Integer formRecordID)  throws ApplicationException {
	    PreparedStatement preStat = null;
	    ResultSet rs = null;
	    StringBuffer sqlStat = new StringBuffer();
	    synchronized(dbConn) {
	      try {
	        sqlStat.append("SELECT A.ID, A.FORM_RECORD_ID, A.FORM_PAGE_ID, A.FORM_SECTION_ID, A.PAGE_HTML, A.VERSION, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
	        sqlStat.append("FROM   FORM_SUBMISSION_HTML A ");
	        sqlStat.append("WHERE  A.FORM_RECORD_ID = ? AND A.RECORD_STATUS = ? ");
	        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
	        this.setPrepareStatement(preStat, 1, formRecordID);
	        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
	        rs = preStat.executeQuery();
	        if (rs.next()) {
	         return true;	
	        }
	        else{
	         return false;
	        }
	       }  catch (SQLException sqle) {
	        log.error(sqle, sqle);
	        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
	      } catch (Exception e) {
	        log.error(e, e);
	        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
	      } finally {
	        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
	        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
	      }
	    }
       }
}
